//
//  ZhongZhiTableViewCell.m
//  明和智能
//
//  Created by 李李善 on 2018/8/24.
//  Copyright © 2018年 inno. All rights reserved.
//

#import "ZhongZhiTableViewCell.h"
#import "BaseCollectionViewCell.h"
@interface ZhongZhiCollectionViewCell : BaseCollectionViewCell
@end
@implementation ZhongZhiCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor redColor];
        self.borderWidth = 0.5;
        self.borderColor = [UIColor colorWithHexString:@"#dbdbdb"];
        self.textLabel.textColor = [UIColor blackColor];
        self.textLabel.font = kSysFont(kFitW(13));
        WSELF(weakSelf);
        [self onMainSetSubViewFrame:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
            [weakSelf.textLabel sizeToFit];
            weakSelf.textLabel.centerX = size.width/2;
            weakSelf.textLabel.centerY = size.height/2;
        }];
        
    }
    return self;
}
-(void)update:(id)model collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.textLabel.text = model;
    self.backgroundColor = self.selected?hexCOLOR(@"FD8F25"):[UIColor whiteColor];
}

@end

@interface ZhongZhiTableViewCell()<MCImageScrollViewDataSource>
@property(nonatomic)CGSize size;
@end


@implementation ZhongZhiTableViewCell

-(void)onAsInitAddView:(UIView *)view forViewController:(UIViewController *)ViewController forDataSource:(id)dataSource AtIndexPath:(NSIndexPath *)indexPath
{
    self.backgroundColor = [UIColor clearColor];

    MCImageScrollView *imageScrollView = ({
        MCImageScrollView *l  = [[MCImageScrollView alloc]initWithClass:[ZhongZhiCollectionViewCell class] scrollDirection:(UICollectionViewScrollDirectionVertical)];
        l.dataSource = self;
        l.delegate = ViewController;
        [l updateViewForImages:@[@"10元",@"30元",@"50元",@"100元",@"300元",@"500元"]];
        l.backgroundColor = [UIColor clearColor];
        [view addV:l];
        l;
    });
    
//    ZhongZhiCollectionViewCell *cell = (id)[imageScrollView.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
//    cell.selected = YES;
//    [imageScrollView.collectionView reloadData];
    
    
    WSELF(weakSelf);
    [self onMainSetSubViewFrame:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
        imageScrollView.frame = CGRectMake(kFitW(15),0,size.width-kFitW(30),size.height);
        CGFloat w = (size.width-kFitW(30)-kFitW(13)*2)/3;
        CGFloat h = (size.height-kFitW(13))/2;
        weakSelf.size = CGSizeMake(w,h);
    }];

}


-(UIEdgeInsets)imageScrollView:(UICollectionView *)collectionView imageCellForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsZero;
}
//iten 之间的间距
- (CGFloat)imageScrollView:(UICollectionView *)collectionView lineSpacingForSectionAtIndex:(NSInteger)section
{
    return kFitW(13);
}
//行之间的间距
- (CGFloat)imageScrollView:(UICollectionView *)collectionView interitemSpacingForSectionAtIndex:(NSInteger)section
{
    return kFitW(13);
}
- (CGSize)imageScrollView:(UICollectionView *)collectionView sizeForItemAtIndexPath:(NSIndexPath *)indexPath

{
    return self.size;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end


@interface ZhongZhiTableViewCell1()

@end


@implementation ZhongZhiTableViewCell1

-(void)onAsInitAddView:(UIView *)view forViewController:(UIViewController *)ViewController forDataSource:(id)dataSource AtIndexPath:(NSIndexPath *)indexPath
{
    self.backgroundColor = [UIColor clearColor];
   
    UIView *bjView = ({
        UIView *l  = [UIView new];
        l.backgroundColor = [UIColor whiteColor];
        [view addV:l];
        l;
    });
    UILabel *money = ({
        UILabel *l  = [UILabel new];
        l.textColor = [UIColor blackColor];
        l.text = @"输入充值金额(元):";
        l.font = kSysFont(kFitW(13));
        [bjView addV:l];
        l;
    });
    UITextField *money1 = ({
        UITextField *l  = [UITextField new];
        l.textColor = hexCOLOR(@"FD8F25");
        l.textAlignment = NSTextAlignmentLeft;
        l.placeholder = @"输入充值金额";
        l.text = @"10";
        l.font = kSysFont(kFitW(13));
        [bjView addV:l];
        l;
    });
    [self onMainSetSubViewFrame:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
        bjView.size  = CGSizeMake(size.width-kFitW(30),size.height-kFitH(13));
        bjView.left = kFitW(15);
        bjView.bottom =size.height;
        
        [money sizeToFit];
        money.left = kFitW(15);
        money.centerY = bjView.height/2;

        money1.size = CGSizeMake(bjView.width-money.right-kFitW(15),bjView.height);
        money1.left =money.right+kFitW(15);
        money1.centerY = bjView.height/2;
    }];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

@interface ZhongZhiTableViewCell2()

@end


@implementation ZhongZhiTableViewCell2

-(void)onAsInitAddView:(UIView *)view forViewController:(UIViewController *)ViewController forDataSource:(id)dataSource AtIndexPath:(NSIndexPath *)indexPath
{
    self.backgroundColor = [UIColor clearColor];
    
    UIView *bjView = ({
        UIView *l  = [UIView new];
        l.backgroundColor = [UIColor whiteColor];
        [view addV:l];
        l;
    });
    UIImageView *imageV = ({
        UIImageView *l  = [UIImageView new];
        l.highlightedImage = [UIImage imageNamed:@"huiyuan_hover"];
        l.image = [UIImage imageNamed:@"huiyuan"];
//        l.highlighted = indexPath.row==0?YES:NO;
        [l sizeToFit];
        [bjView addV:l];
        l;
    });
    
    self.accessoryView = imageV;
    WSELF(weakSelf);
    [self onMainSetSubViewFrame:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
        
        bjView.size  = CGSizeMake(size.width-kFitW(30),size.height-kFitH(13));
        bjView.left = kFitW(15);
        bjView.top =0;
        
        [weakSelf.imageView sizeToFit];
        weakSelf.imageView.centerY = bjView.height/2;
        weakSelf.imageView.left= bjView.left+kFitW(10);
        
        [weakSelf.textLabel sizeToFit];
        weakSelf.textLabel.centerY = bjView.height/2;
        weakSelf.textLabel.left= weakSelf.imageView.right+kFitW(10);
        
        weakSelf.accessoryView.centerY =bjView.height/2;
        

        
    }];
}
-(void)update:(NSDictionary *)model forTableView:(UITableView *)tableView AtIndexPath:(NSIndexPath *)indexPath
{
    self.imageView.image = [UIImage imageNamed:model[@"imageName"]];
    self.textLabel.text = model[@"title"];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    UIImageView *imageV = (id)self.accessoryView;
    imageV.highlighted = selected;
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

@end

@implementation ZhongZhiHeaderFooterView
-(void)onAsInitAddView:(UIView *)view forViewController:(UIViewController *)ViewController forDataSource:(id)dataSource AtSection:(NSInteger)section
{WSELF(weakSelf);
    [self onMainSetSubViewFrame:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
        [weakSelf.textLabel sizeToFit];
        weakSelf.textLabel.left = kFitW(15);
        weakSelf.textLabel.centerY = size.height/2;
    }];
}
-(void)update:(id)model forTableView:(UITableView *)tableView AtSection:(NSInteger)section
{
    self.backgroundColor = [UIColor clearColor];
    self.textLabel.textColor = [UIColor blackColor];
    self.textLabel.font = kSysFont(kFitW(13));
    self.textLabel.text = model;
}

@end
